package com.own.business.system.user.controller.user;

import com.own.business.system.user.business.entity.form.GetSensitiveTokenByPhoneForm;
import com.own.business.system.user.business.entity.vo.SensitivePhoneCodeVo;
import com.own.business.system.user.business.service.SensitivePhoneService;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.login.util.SessionUserUtil;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.component.sensitive.check.entity.SensitiveTokenVo;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * SensitivePhoneController
 *
 * @author chenxueli
 * @date 2023-11-04 16:10:25
 */
@Slf4j
@Tag(name = "敏感信息（手机号）" + ConstantBeanSuffix.CONTROLLER)
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + "/sensitive/phone")
public class SensitivePhoneController extends BaseController {

    @Resource
    private SensitivePhoneService sensitivePhoneService;

    @LogOperationAop
    @Operation(summary = "获取修改支付密码的验证码（手机验证码）")
    @GetMapping("/change/code")
    public ResultModel<SensitivePhoneCodeVo> getSensitivePhoneCode() {
        var loginUser = SessionUserUtil.getLoginUser();
        var vo = sensitivePhoneService.getSensitivePhoneCode(loginUser.userId());
        return R.success(vo);
    }

    @LogOperationAop
    @Operation(summary = "根据手机验证码获取修改支付密码的token")
    @PostMapping("/change/token/phone")
    public ResultModel<SensitiveTokenVo> getSensitiveChangeTokenByPhone(
            @RequestBody GetSensitiveTokenByPhoneForm form
    ) {
        var loginUser = SessionUserUtil.getLoginUser();
        var vo = sensitivePhoneService.getSensitiveChangeTokenByPhone(loginUser.userId(), form);
        return R.success(vo);
    }

}
